package com.kuaimacode.kframework.admin.services.sys;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kuaimacode.kframework.admin.services.agent.SysAgentService;
import com.kuaimacode.kframework.mybatis.mapper.sys.SysAreaMapper;
import com.kuaimacode.kframework.mybatis.models.agent.SysAgent;
import com.kuaimacode.kframework.mybatis.models.sys.SysArea;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

/**
 * @author qinyong
 * @Title:
 * @Package com.kuaimacode.kframework.admin.services.sys
 * @Description: created by IntelliJ IDEA
 * @date 2019-04-11 21:14
 */
@Service
public class SysAreaService extends ServiceImpl<SysAreaMapper, SysArea> {

    @Autowired
    private SysAgentService agentService;

    public List<SysArea> findAll() {
        return baseMapper.selectList(null);
    }

    public List<SysArea> notAddList() {
        List<SysAgent> agents = agentService.list();
        List<SysArea> areas = this.list();
        Iterator<SysArea> iterator = areas.iterator();
        while (iterator.hasNext()) {
            SysArea next = iterator.next();
            if (CollectionUtils.isNotEmpty(agents)) {
                for (SysAgent agent : agents) {
                    if (agent.getId().equals(next.getAreaCode())) {
                        iterator.remove();
                        break;
                    }
                }
            }
        }
        return areas;
    }
}
